<?php
include_once("commonFunctions.php");
include_once("Classes/Dealer.php");
@$dealer = new Dealer($_SESSION['dealerCode']);

$notes = $_POST['notes'];
$nextStatus = $_SESSION['nextStatus'];
$tt = new TT($_SESSION['ttid']);
?>
<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <META HTTP-EQUIV="refresh" CONTENT="10;URL=/main.php"/>
        <link rel="stylesheet" type="text/css" href="CSS/formStyle.css" />
        <script type="text/javascript" src="JavaScript/showTickets_history_ajax.js"></script>
        <title>TTS - Updating Status For Ticket # <?php $tt->id ?></title>
    </head>
    <body onload="disable(); ">
        <div id="logo">
            <img src="logo.png" />
        </div>
        <div id="menu">
            <a href="index.php" class="menuitem">Login</a>
            <a href="main.php" id="activeitem" class="menuitem">View Tickets</a>
            <a href="submitNewTT.php" class="menuitem">Submit New Ticket</a>
            <p id="districtname">South Georgia</p>
        </div>
        <div id="infobox">
            <div id="infotext">
                <h3>View tickets</h3>
                <p>This page will allow you to lookup all tickets within the Cellular Sales TTS system</p>
            </div>
        </div>
        <div id="header">
            <?php tts_getheader(); ?>
        </div>
        <center>Your ticket has been updated to <?php echo $nextStatus ?>. Redirecting to Main in 10 seconds.<br/>
            A text has been sent to <?php echo $tt->submittedByName ?> notifying them of the change.</center>
        <?php
            tts_updateStatus($nextStatus, $tt, $dealer->dealerCode, $notes);
            $submittedBy = new Dealer($tt->submittedBy);
            $subject = 'Your ticket# ' . $tt->id . ' has just been updated to ' . $nextStatus . ' by ' . $dealer->fullName;
            tts_SendText($submittedBy->phone, $subject, $notes);
        ?>
    </body>
</html>